package com.xiaoxi.open.design.structural.compositepattern.composite.company;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Dept
 * @Description
 * @Author xiaoxi
 * @Date 2024/10/20 22:07
 * @Version 1.0
 */
@Slf4j
public class Dept implements Company {

    private final List<Company> deptList = new ArrayList<>();
    private String name;

    public Dept(String name) {
        this.name = name;
    }

    @Override
    public void add(Company company) {
        if (company instanceof Employee) {
            deptList.add(0, company);
        } else {
            deptList.add(company);
        }
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void printList() {
        log.info("当前部门：{}", name);

        for (Company next : deptList) {
            next.printList();
        }
    }
}
